import {userLogin} from '../api/user'
import router from '../router';//引入路由
export default{
    namespaced:true,
    state:()=>({
        userIfo:null
    }),
    mutations: {
        initUserIfoMut(state, uIfo) {
            state.userIfo=uIfo;
            if(uIfo){
                localStorage.setItem('userIfo',JSON.stringify(uIfo))
            }else{
                localStorage.removeItem('userIfo')
            }
        },
    },
    actions: {
        userLoginAct(context, {userIfo,target}) {
            userLogin(userIfo).then(res=>{
                context.commit('initUserIfoMut',res.data.data)
                if(res.data.code===122)
                    router.push(target)
            })
        }
    }
}